import { SPI } from '../conn/SPI'
import {AppModel} from '../AppModel'
import { PartSlaver } from './PartBase'
import config from './config/BeScreen096i.json'

export class BeScreen096i extends PartSlaver {

    constructor(_model: AppModel){
        super(_model, config)
    }

    // serial(): SPI | undefined {
    //     return (this.studs[2][1].bus?.findCable() || this.studs[3][0].bus?.findCable() || this.studs[3][1].bus?.findCable()) as SPI
    // }
    
    public generateSetupCode(indent=0){
        return `${"\t".repeat(indent)}${this.remoteVar()} = new (require("besdk/driver/screen")).BeScreen096i()`
    }

    public generateBeginCode(indent=0){
        // let serial = this.serial()
        // if(!serial || !serial.isValid()) {
        //     return `${"\t".repeat(indent)}/* ${this.instanceName} SPI串口线路尚未配置(MOSI/SCK未正确连接) */`
        // }
        // let pinDC = this.studs[2][0]
        // if(!pinDC.bus){
        //     return `${"\t".repeat(indent)}/* ${this.instanceName} DC 接口未正确连接) */`
        // }
        // let pinCS = this.studs[3][1]
        // if(!pinCS.bus){
        //     return `${"\t".repeat(indent)}/* ${this.instanceName} CS 接口未正确连接) */`
        // }

        // let gpioDC = pinDC.bus.findHostStud()
        // if(!gpioDC){
        //     return `${"\t".repeat(indent)}/* ${this.instanceName}  DC 接口未连接到主机零件) */`
        // }
        // let gpioCS = pinCS.bus.findHostStud()
        // if(!gpioCS){
        //     return `${"\t".repeat(indent)}/* ${this.instanceName}  CS 接口未连接到主机零件) */`
        // }

        // return `${"\t".repeat(indent)}${this.remoteVar()}.begin( ${serial.name}, ${gpioCS.info.pin}, ${gpioDC.info.pin}, ${this.spiFreq()} )`
        return null
    }

    public spiFreq() {
        return 26000000
        // let serial = this.serial()
        // return (serial && serial.isIoMux())? 50000000: 26000000
    }
}